package lock;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @program: javase
 * @description: 锁的对象是调用者
 * @author: lld
 * @create: 2021-04-17 21:56
 **/
/**
*  1.谁先获取到对象的锁，就先调用，其他等待
 * 2.非同步方法无关锁
 * 3.静态同步方法 锁对象是类的Class对象
**/
public class LockObject {
    public static void main(String[] args) {
        Data data = new Data();
        Data data1 = new Data();
        new Thread(()->data.play()).start();
        new Thread(()->data1.call()).start();
//        new Thread(()->data1.eat()).start();
    }

}
class Data{
    public static synchronized void play(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("玩游戏");
    }
    public synchronized void call(){
        System.out.println("打电话");
    }
    public static synchronized void eat(){
        System.out.println("吃东西");
    }
}
